package com.hdax.dm.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.entity.base.Area;
import com.hdax.dm.entity.item.ItemType;
import com.hdax.dm.item.dto.AreaDto;
import com.hdax.dm.item.feign.BaseFeign;
import com.hdax.dm.item.mappers.ItemTypeMapper;
import com.hdax.dm.item.service.ItemSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ItemSearchServiceImpl extends ServiceImpl<ItemTypeMapper, ItemType> implements ItemSearchService {

    @Autowired
    private BaseFeign baseFeign;

    @Override
    public List<ItemType> itemTypes(Long parent) {
        QueryWrapper<ItemType> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent",parent);
        return list(queryWrapper);
    }

    @Override
    public List<AreaDto> queryCities() {
        List<Area> areas = baseFeign.areas();
        List<AreaDto> areaDtos = new ArrayList<>();
        areas.forEach(a->{
            AreaDto dto = AreaDto.builder()
                    .id(a.getId())
                    .name(a.getName())
                    .build();
            areaDtos.add(dto);
        });
        return areaDtos;
    }
}
